#region Terms of Usage
/*
 * Copyright 2006 Sameera Perera
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
#endregion

using System;
using System.Collections.Generic;
using System.Text;

namespace needle.Services.soab.Connectivity
{
    /// <summary>
    /// Enumeration to define connection state. Used by the ConnectionManager to define the physical connectedness
    /// of the system, and by the ServiceAgentManager to define the system-wide connectedness
    /// </summary>

    public enum ConnectionState
    {
        /// <summary>
        /// <para>  Connection state is Offline</para>
        /// </summary>
        Offline=0,
        /// <summary>
        /// <para> Connection state is Online</para>
        /// </summary>
        Online=1,
        /// <summary>
        /// <para> Connection state is Unknown</para>
        /// </summary>
        Unknown=-1
    };

    /// <summary>
    /// This is the delegate used by the ConnectionManager to define the 
    /// event it uses to broadcast its state changes
    /// </summary>
    /// <param name="sender">Sender of the event</param>/>
    /// <param name="e">Event arguments</param>/>
    public delegate void ConnectionStateChangedEventHandler( object sender,
        ConnectionStateChangedEventArgs e );

    /// <summary>
    /// EventArgs for ConnectionState changes. This class represents the connection states of the physical connection, 
    /// rather that the application.
    /// </summary>
    public class ConnectionStateChangedEventArgs : EventArgs
    {
        private ConnectionState newState;
        private ConnectionState oldState;

        /// <summary>
        /// Defines the data that is sent along with the event.
        /// </summary>
        /// <param name="oldState">State connection is transitioning from</param>
        /// <param name="newState">State connection is transitioning to</param>
        public ConnectionStateChangedEventArgs( ConnectionState oldState, ConnectionState newState )
        {
            this.newState = newState;
            this.oldState = oldState;
        }

        /// <summary>
        /// Returns the current physical state of the connection
        /// </summary>
        /// <value>The current connection state</value>
        public ConnectionState CurrentState { get { return newState; } }

        /// <summary>
        /// Returns the previous physical state of the connection
        /// </summary>
        /// <value>The original connection state</value>
        public ConnectionState OriginalState { get { return oldState; } }
    }
}
